<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="pc/include :: header('文档分类')" />

    <link th:href="@{/js/ui-table/ui-table.css}" rel="stylesheet"/>
</head>
<body>
<th:block th:include="pc/include :: top" />
<div class="iw">
    <div class="crumbs">
        <p>当前位置：<a href="/">首页</a>
            <span th:if="${type}!=''" th:remove="tag"> > </span>
            <span th:utext="${type}" th:remove="tag"></span>
            <span th:if="${type}==''" th:remove="tag"> > </span>
        </p>
    </div>
    <div class="list_left">
        <div class="list_type">
            <a class="type_all" th:classappend="${first}==0?'active'" href="javascript:;" th:attr="goto=@{doc.html}" >
                <p>全部文档</p><span th:text="${total}"></span>
            </a>
            <ul class="type_parent">
                <li>

                    <a th:if="${first}!=0" href="javascript:;" th:attr="goto=@{doc.html(first=${parent_array.typeid})}"  th:classappend="${parent_array.typeid}==${first}?'active'">
                        <p th:text="${parent_array.typename}"></p><span></span>
                    </a>

                    <ul class="type_chlid">

                        <li th:each="entry :${child_array}">
                            <a  href="javascript:;" th:attr="goto=@{doc.html(first=${entry.typeid})}"  th:classappend="${entry.typeid}==${first}?'active'">
                                <p th:text="${entry.typename}"></p><span></span>
                            </a>
                        </li>

                    </ul>
                </li>
            </ul>
        </div>

    </div>
    <div class="list_right">
        <div class="list-filter" th:each="entry :${filter_array}" th:if="${entry.key} == 0 " >

            <div th:each="entry1,userStat :${entry.value}" >
                <h7 th:text="${entry1.name}">
                    </h7>
                <div class="filter-items">
                    <a th:if="${userStat.index}==0"  th:classappend="${one}==0?'active'" href="javascript:void(0)" data-id="0"    th:attr="data-index=${userStat.index}"  onclick="gettype(this)"  >全部</a>
                    <a th:if="${userStat.index}==1"  th:classappend="${two}==0?'active'" href="javascript:void(0)" data-id="0"    th:attr="data-index=${userStat.index}"  onclick="gettype(this)"  >全部</a>
                    <a th:if="${userStat.index}==2"  th:classappend="${three}==0?'active'" href="javascript:void(0)" data-id="0"    th:attr="data-index=${userStat.index}"  onclick="gettype(this)"  >全部</a>

                    <a th:if="${userStat.index}==0"  th:classappend="${one}==${entry2.id}?'active'" th:attr="data-id=${entry2.id},data-index=${userStat.index}" href="javascript:void(0)"   onclick="gettype(this)"  th:each="entry2 :${filter_array[entry1.id]}" th:text="${entry2.name}"   ></a>
                    <a th:if="${userStat.index}==1"  th:classappend="${two}==${entry2.id}?'active'" th:attr="data-id=${entry2.id},data-index=${userStat.index}" href="javascript:void(0)"   onclick="gettype(this)"  th:each="entry2 :${filter_array[entry1.id]}" th:text="${entry2.name}"   ></a>
                    <a th:if="${userStat.index}==2"  th:classappend="${three}==${entry2.id}?'active'" th:attr="data-id=${entry2.id},data-index=${userStat.index}" href="javascript:void(0)"   onclick="gettype(this)"  th:each="entry2 :${filter_array[entry1.id]}" th:text="${entry2.name}"   ></a>

                </div>
            </div>

        </div>
        </div>

      <div class="list-header">
            <ul>
                <li><a href="javascript:;" th:attr="goto=@{doc.html(first=${first},second=${filterstr},third=1)}" th:classappend="${third}==1?'active'">最新<i></i></a></li>
                <li><a href="javascript:;" th:attr="goto=@{doc.html(first=${first},second=${filterstr},third=2)}" th:classappend="${third}==2?'active'">最热<i></i></a></li>
                <li><a href="javascript:;" th:attr="goto=@{doc.html(first=${first},second=${filterstr},third=3)}" th:classappend="${third}==3?'active'">价格<i></i></a></li>
                <li><a href="javascript:;" th:attr="goto=@{doc.html(first=${first},second=${filterstr},third=4)}" th:classappend="${third}==4?'active'">VIP免费文档</a></li>
                <li><a href="javascript:;" th:attr="goto=@{doc.html(first=${first},second=${filterstr},third=5)}" th:classappend="${third}==5?'active'">推荐文档</a></li>
            </ul>
            <div>
                <a class="next unselect">&rsaquo;</a>
                <a class="prev unselect">&lsaquo;</a>
            </div>
        </div>
        <div class="list_body" style="float: left">
            <ul>
                <li th:each="item,userStat :${docs}">
                    <a th:href="@{/detail.htm(docid=${item.docid})}">
                        <div class="thum">
                            <img th:src="${item.path}" class="zoom_img s">
                            <i th:if="${item.downpay}==0" class="mf">免费</i>
                            <i th:unless="${item.downpay==0}" class="ff"><span th:text="${item.downpay}"></span></i>
                            <i th:if="${item.isvip}" class="vmf">vip免</i>
                            <i class="rb" th:classappend="${item.exten}"></i>
                        </div>
                    </a>
                    <div class="thumlist">
                        <h2><a th:classappend="${item.isimp}?'h2'"  th:href="@{/detail.htm(docid=${item.docid})}"><i></i><span th:text="${item.title}" th:remove="tag"></span></a></h2>
                        <ul>
                            <li class="li1"><a th:href="@{'/user/doclist/'+${item.userid}}"> <i class="fa fa-user"></i> <span th:text="${item.nickname}" th:remove="tag"></span></a></li>
                            <li class="li2"><span th:text="${item.readcount}" th:remove="tag"></span> 次阅读</li>
                            <li class="li3"><span th:text="${item.downcount}" th:remove="tag"></span> 次下载</li>
                            <li class="li4"><i class="fa fa-clock-o"></i><span th:text="${item.insertdate}" th:remove="tag"></span></li>
                        </ul>
                        <div>
                            <span>简介：</span>
                            <p th:text="${item.word}"></p>
                        </div>
                    </div>
                </li>

            </ul>
        </div>
        <div class="pages">
        </div>
    </div>
</div>
<th:block th:include="pc/include :: footer" />
<script>
    $(function() {
        $(".pages").html(CreatPage('[(${cpage})]', '[(${pagesize})]', '[(${total})]', "/doc.html?first=[(${first})]&second=[(${filterstr})]&third=[(${third})]&pageNum={PageCurrent}&pageSize=10"));
    });
</script>
<script>
    function  gettype(obj)
    {
        var filter = [];
        $(".filter-items a").each(function() {
            if ($(this).hasClass("active")) {
                filter.push($(this).attr("data-id"));
            }
        });
        var index = $(obj).attr("data-index");
        var newvalue = $(obj).attr("data-id");
        filter = replaceAtIndex(filter,index,newvalue)
        second = filter.join("-");

        location.href="/doc.html?first=[(${first})]&second="+second+"&third=[(${third})]";

    }
    function replaceAtIndex(array, index, newItem) {
        if (index >= 0 && index < array.length) {
            // 创建一个新数组，避免修改原数组
            const newArray = [...array];
            // 替换指定索引的元素
            newArray[index] = newItem;
            return newArray;
        }
        // 如果索引无效，返回原数组或抛出错误
        return array;
    }
</script>